package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.risk.BpTeam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface BpTeamRepository extends JpaRepository<BpTeam, Long>, JpaSpecificationExecutor<BpTeam> {


    List<BpTeam> findByReportDateAndTeamDepartId(@Param("reportDate") LocalDate reportDate,
                                                 @Param("teamDepartId") Long teamDepartId);


    @Query(value = "SELECT a FROM BpTeam a WHERE a.createTime =(SELECT MAX(b.createTime) FROM BpTeam b WHERE b.teamDepartId =?1 " +
            "and b.tenentId=?2 and b.orgCode like ?3%)")
    BpTeam findLastTeam(Long currentDepartId, Long currentTenentId, String currentOrgCode);
}
